<?php

namespace app\admin\model;

use think\Model;

class ShareEntrust extends Model
{
    // 表名
    protected $name = 'share_entrust';

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    public function getStatusList()
    {
        return [
			'0' => '已取消', 
			'1' => '委托中', 
			'2' => '已成交',
		];
    }

    public function getModeList()
    {
        return [
			'buy'   => '买入', 
			'sell' => '卖出', 
		];
    }

    public function getIsAutoList()
    {
        return [
			'1' => __('Is_auto 0'), 
			'1' => __('Is_auto 1')
		];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getModeTextAttr($value, $data)
    {
        return 'xxx';
        $value = $value ? $value : (isset($data['mode']) ? $data['mode'] : '');
        $list = $this->getModeList();
        //var_dump($value,$list);
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIsAutoTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_auto']) ? $data['is_auto'] : '');
        $list = $this->getIsAutoList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
